import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'

export const userStore = defineStore("user", () => {
	const userinfo = ref({
		username: '',
		mobilePhoneNumber: ''
	});
	const isLogin = ref(false);

	function addUserInfo(username, mobilePhoneNumber) {
		userinfo.value.username = username;
		userinfo.value.mobilePhoneNumber = mobilePhoneNumber;
		isLogin.value = true;
		localStorage.setItem('userinfo', JSON.stringify(userinfo.value));
	}

	function clearUserInfo() {
		userinfo.value = {};
		isLogin.value = false;
		localStorage.removeItem('userinfo');
	}
	
	let currentPos = ref({
		longitude: 0,
		latitude: 0
	})

	function setPos(longitude, latitude) {
		currentPos.value.longitude = longitude
		currentPos.value.latitude = latitude
		console.log(currentPos.value)
	}

	return {
		userinfo,
		isLogin,
		addUserInfo,
		clearUserInfo,
		setPos,
		currentPos
	}
})